{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to Integration\n",
    "\n",
    "Integrals are the inverses of derivatives. More importantly, using integration provides a way to compute the area under the curve of most any function. There are many applications for integration. For example, if you need to compute a probability of some occurance between limits (which we'll discuss later in this course), then you will use an integral.\n",
    "\n",
    "Let's start with a simple function:\n",
    "\n",
    "$$f(x)=x$$\n",
    "\n",
    "We can plot this function as a line. Run the code below to plot the function for the range 0 to 10:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xd8ldXhx/HPIYyEhD3C3siQMiRskIQ9g3UVLKgYxK1VqxWt1bbWun9qS62IVttaaSu23gxIIBI2SFgiIBshGGSPhAAZ5/cH+fVF+aGEkHtP7n2+73+Suzjfw03yvc9zn+dcY61FRES8q4LrACIi4paKQETE41QEIiIepyIQEfE4FYGIiMepCEREPE5FICLicSoCERGPUxGIiHhcRdcBSqJu3bq2RYsWpXpsbm4ukZGRZRuonNOcvUFzDn1XOt/Vq1cfstbWu9T9gqIIWrRoQWZmZqkem5GRQWxsbNkGKuc0Z2/QnEPflc7XGPN1Se6nXUMiIh6nIhAR8TgVgYiIx6kIREQ8TkUgIuJxfisCY8x7xpgDxpgvz7uutjFmnjFmW/HXWv4aX0RESsafWwTvAyMuuO4JIN1a2xZIL74sIiIO+a0IrLWLgCMXXD0O+KD4+w+A6/w1vohIMDu+5zjbf7+dooIiv49l/PmZxcaYFkCStbZT8eVj1tqa591+1Fp70d1DxpipwFSA6Ojo7rNmzSpVhpycHKKiokr12GClOXuD5hyabJHlG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2RBgl7X2oLU2H/gE6Os4U6B8a4xpCFD89YA/BgnlIlgFtDXGtDTGVObcm0s+x5n8xhhjOLffeLO19jXXeQLBWjvNWtvEWtuCc8/vZ9bakH6laK3dD+w1xrQrvmowsMlhpEDYA/Q2xlQt/jkfTIi/QX4eH3Bb8fe3AZ/6YxAnn1kcCNbaAmPM/UAq544yeM9au9FxLH/qB0wCNhhj1hVf92Tx50NLaHkA+LD4Bc5OYLLjPH5lrV1pjPkYWMO5o+PWEoJnGBtjPgJigbrGmCzgGeAF4B/GmATOFeJNfhlbZxaLiHhbKO8aEhGRElARiIh4nIpARMTjVAQiIh6nIhAR8TgVgYiIx6kIREQ8TkUgUgrGmB7GmC+MMeHGmMjitfI7uc4lUho6oUyklIwxzwHhQATn1v/5reNIIqWiIhAppeIlHlYBp4G+1tpCx5FESkW7hkRKrzYQBVTj3JaBSFDSFoFIKRljfJxb/rol0NBae7/jSCKlErKrj4r4kzHmVqDAWvu34s/HXmaMGWSt/cx1NpHLpS0CERGP03sEIiIepyIQEfE4FYGIiMepCEREPE5FICLicSoCERGPUxGIiHicikBExOP+Fyx2ng7JieH+AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "# Define function f\n",
    "def f(x):\n",
    "    return x\n",
    "\n",
    "# Create an array of x values from 0 to 10\n",
    "x = range(0, 11)\n",
    "\n",
    "# Get the corresponding y values from the function\n",
    "y = [f(a) for a in x]\n",
    "\n",
    "# Set up the plot\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('f(x)')\n",
    "plt.grid()\n",
    "\n",
    "# Plot x against f(x)\n",
    "plt.plot(x,y, color='purple')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Performing Integration\n",
    "\n",
    "The *integral* of a function is the area under it - in this case, the area under the purple diagonal line down to the x-axis.\n",
    "\n",
    "So how do you find the integral of a function? well, for our simple function $f(x) = x$, the formula for an integral is written as follows:\n",
    "\n",
    "$$\\int f(x)\\;dx$$\n",
    "\n",
    "The $\\int$ symbol shows that this formula is an integral. The $dx$ indicates that the integration is with respect to the $x$ variable. Note that since $f(x) = x$, we could also write this integral formula as $\\int x\\;dx$\n",
    "\n",
    "So, what  is the integral of $x\\ dx$? To answer this question, we need the *antiderivative* of ***f*** - in other words we need to find a function which has a derivative matching the output of $f$, which is just $x$. Using the power rule in reverse, a function that has the derivative $x$ would be $\\frac{1}{2} x^2$\n",
    "\n",
    "So, the *unbound* integral formula for $f$ with respect to $x$ can be written as:\n",
    "\n",
    "$$\\int f(x)\\;dx = \\frac{1}{2} x^2$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integration between Limits\n",
    "\n",
    "Now that we have the unbound integral formula, we can use it to find the integral between specific start and end points. Let's suppose we want to find the area under the function between the $x$ values 0 and 2. In other words, the *integral* of $f$ for the range 0 to 2 with respect to $x$.\n",
    "\n",
    "Run the following code to re-plot the function and show the area we're interested in:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl8VNXB//HPYQ0Q9iXsmyCIyCIREUQS9jVYV7S4YDBuVKtWK1p/2mqt+6O21Iroo22tPK3ax8kCCQTCDpKwiIDsWzCRfUlIyHZ+f5CnL0pRIGTmzMz9vv9JZuN8D5PMN/fOvWeMtRYREfGuKq4DiI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gG1DLGVANqc5ZPNQx11tqFwKEzrh4PfFz+/cfA9f4YO5yLoBWw57TL2XjghRHAGNMe6A2scJskIN4CngTKXAcJkI7AfuC/y3eHzTDG1HEdyp+stXuB14HdQA5w1Fqb5jZVwERZa3Pg1B97QDN/DBLORWDOcl3YHyJljIkEPgd+bq095jqPPxljxgL7rLVZrrMEUDXgSuBda21vIB8/7S4IFuX7xccDHYCWQB1jzES3qcJLOBdBNtDmtMutCcPNydMZY6pzqgQ+sdZ+4TpPAAwA4owxOzm162+wMeavbiP5XTaQba39v629zzhVDOFsKLDDWrvfWlsMfAH0d5wpUL43xrQAKP+6zx+DhHMRrAQ6G2M6GGNqcOrNJZ/jTH5jjDGc2m+80Vr7pus8gWCtnWqtbW2tbc+p53eetTas/1K01uYCe4wxXcqvGgJscBgpEHYD/Ywxtct/zocQ5m+Qn8YH3FX+/V3Al/4YxMlnFgeCtbbEGDMFSOXUUQYfWmvXO47lTwOAO4B1xpg15dc9Xf750BJefgZ8Uv4HznZgkuM8fmWtXWGM+QxYxamj41YThmcYG2M+BWKAJsaYbOA54GXg78aYeE4V4s1+GVtnFouIeFs47xoSEZHzoCIQEfE4FYGIiMepCEREPE5FICLicSoCERGPUxGIiHicikCkAowxVxljvjbGRBhj6pSvld/ddS6RitAJZSIVZIx5EYgAanFq/Z/fOY4kUiEqApEKKl/iYSVQCPS31pY6jiRSIdo1JFJxjYBIoC6ntgxEQpK2CEQqyBjj49Ty1x2AFtbaKY4jiVRI2K4+KuJPxpg7gRJr7d/KPx97qTFmsLV2nutsIhdKWwQiIh6n9whERDxORSAi4nEqAhERj1MRiIh4nIpARMTjVAQiIh6nIhAR8TgVgYiIx/1/ryfZgFtWC2cAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Set up the plot\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('f(x)')\n",
    "plt.grid()\n",
    "\n",
    "# Plot x against f(x)\n",
    "plt.plot(x,y, color='purple')\n",
    "\n",
    "# show area for integral\n",
    "section = np.arange(0, 2, 1/20)\n",
    "plt.fill_between(section,f(section), color='orange')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We call the start and end point the **limits** of the integral. The lower limit is placed as a subscript of the integral sign. The upper limit is placed as a superscript of the integral sign. Using this notation the integral of $f(x)$ from $0$ to $2$ is written as follows:\n",
    "\n",
    "$$\\int_0^2 f(x)\\;dx$$\n",
    "\n",
    "The integral is evaluated by subtracting the value of the integrand at the lower limit from the integrand at the upper limit; and since we know the formula based on our antiderivative function, the integral can be evaluated in the following manner.\n",
    "\n",
    "$$\\int_0^2 f(x)\\;dx\\\\ = \\frac{1}{2} x^2\\ \\big|_0^2\\\\\n",
    "= \\frac{1}{2} 2^2 - \\frac{1}{2} 0^2\\\\\n",
    "= \\frac{4}{2} - \\frac{0}{2} x^2\\\\ = 2$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Execute the code in the cell below and verify that the result returned by the ***scipy.integrate.quad*** function in Python is approximately the same as we computed analytically. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.integrate as integrate\n",
    "i, e = integrate.quad(lambda x: f(x), 0, 2)\n",
    "print (i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Another Integral\n",
    "\n",
    "Here is another example for a slightly more complex function. What is the area under the curve of the function $3x^2 + 2x + 1$ between $0$ and $3$?\n",
    "\n",
    "let's look at that function and the area in question:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/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/vsjMbnT3D4KuTeRsaQ9CRETC0jkIEREJSwEhIiJhKSBERCQsBYSIiISlgBARkbAUECIiEpYCQkREwlJAiIhIWP8fjzk9bfuakj8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "from matplotlib.patches import Polygon\n",
    "%matplotlib inline\n",
    "\n",
    "# Define function g\n",
    "def g(x):\n",
    "    return 3 * x**2 + 2 * x + 1\n",
    "\n",
    "# Create an array of x values from 0 to 10\n",
    "x = range(0, 11)\n",
    "\n",
    "# Get the corresponding y values from the function\n",
    "y = [g(a) for a in x]\n",
    "\n",
    "# Set up the plot\n",
    "fig, ax = plt.subplots()\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('f(x)')\n",
    "plt.grid()\n",
    "\n",
    "# Plot x against g(x)\n",
    "plt.plot(x,y, color='purple')\n",
    "\n",
    "# Make the shaded region\n",
    "ix = np.linspace(0, 3)\n",
    "iy = g(ix)\n",
    "verts = [(0, 0)] + list(zip(ix, iy)) + [(3, 0)]\n",
    "poly = Polygon(verts, facecolor='orange')\n",
    "ax.add_patch(poly)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can evaluate this integral just as before, this time using function:\n",
    "\n",
    "$$\\int_0^3 3x^2 + 2x + 1\\;dx$$ \n",
    "\n",
    "We can calculate the antiderivative of $3x^2 + 2x + 1\\;dx$ as $\\frac{3}{3} x^3 + \\frac{2}{2} x^2 + x$, so:\n",
    "\n",
    "$$\\int_0^3= \\frac{3}{3} x^3 + \\frac{2}{2} x^2 + x\\ \\big|_0^3\\\\\n",
    "= \\frac{3}{3} 3^3 + \\frac{2}{2} 3^2 + 3 - \\frac{3}{3} 0^3 - \\frac{2}{2} 0^2 + 0\\\\\n",
    "= 27 + 9 + 3 + 0 + 0 + 0\\\\\n",
    "= 39$$\n",
    "\n",
    "Now, execute the code in the cell below to verify the result:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "i, e = integrate.quad(lambda x: 3 * x**2 + 2 * x + 1, 0, 3)\n",
    "print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the result from the ***scipy.integrate.quad*** function is approximate - the function actually returns an estimated integral (*i* in this case) and also a measure of absolute error (*e*). Run the following code to see what the absolute error was in this case:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The absolute error in this case is extremely small (around $4.3 \\times 10^{-13}$).\n",
    "\n",
    "## Infinite limits\n",
    "\n",
    "In many cases the limits of an integral can be $+/- \\infty$. Perhaps suprisingly, this situation is not really a problem if the function being integrated converges to $0$ at the infinite limit. \n",
    "\n",
    "Here is an example. The function $e^{-5x} \\rightarrow 0$ as $x \\rightarrow \\infty$. Therefore, the integral of this function from some limit to $\\infty$. This integral can be written as follows:\n",
    "\n",
    "$$\\int^{\\infty}_0 e^{-5x} dx$$\n",
    "\n",
    "The code in the cell below computes this integral numerically."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "i, e = integrate.quad(lambda x: np.exp(-x*5), 0, np.inf)\n",
    "\n",
    "print('Integral: ' + str(i))\n",
    "print('Absolute Error: ' + str(e))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This integral converges to a small number with a much smaller error estimate. \n",
    "\n",
    "Here is another example that illustrates why having infinite integration limits is so useful. When computing probabilities it is often necessary to have infinite limits. Don't worry too much about the details of probability theory. This is covered in a later lesson. \n",
    "\n",
    "A Normal distribution with zero mean and a standard deviation of $1$ has the following density function:\n",
    "\n",
    "$$\\frac{1}{2 \\pi} e^{\\frac{-x^2}{\\sqrt(2 \\pi)}}$$\n",
    "\n",
    "It makes sense that the integral of this probability density function from $-\\infty$ to $\\infty$ must be $1.0$. In other words the probability of a Normally distributed event ocurring at all possible values must be $1.0$. \n",
    "\n",
    "The code in the cell below computes the following integral:\n",
    "\n",
    "$$\\int_{-\\infty}^{\\infty} \\frac{1}{2 \\pi} e^{\\frac{-x^2}{\\sqrt(2 \\pi)}} dx$$\n",
    "\n",
    "Execute this code and verify that the result is approximately $1.0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "norms = lambda x: np.exp(-x**2/2.0)/np.sqrt(2.0 * 3.14159)\n",
    "i, e = integrate.quad(norms, -np.inf, np.inf)\n",
    "\n",
    "print('Integral: ' + str(i))\n",
    "print('Absolute Error: ' + str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
